package com.atguigu.tingshu.model.search;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.CompletionField;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.core.suggest.Completion;

@Data
@Document(indexName = "suggestinfo")
@JsonIgnoreProperties(ignoreUnknown = true)//目的：防止json字符串转成实体对象时因未识别字段报错
public class SuggestIndex {

    /**
     * 文档的唯一标识符
     * 使用@Id注解标识该字段为Elasticsearch的文档ID
     */
    @Id
    private String id;

    /**
     * 文档标题字段
     * 使用@Field注解标识该字段为Elasticsearch索引中的字段
     * 指定字段类型为Text，使用standard分析器进行文本分析
     */
    @Field(type = FieldType.Text, analyzer = "standard")
    private String title;

    /**
     * 关键词补全字段
     * 使用@CompletionField注解标识该字段为Elasticsearch的补全建议字段
     * 指定字段使用standard分析器进行索引和查询，最大输入长度为20
     */
    @CompletionField(analyzer = "standard", searchAnalyzer = "standard", maxInputLength = 20)
    private Completion keyword;

    /**
     * 拼音关键词补全字段
     * 与keyword功能类似，但专门用于拼音补全
     */
    @CompletionField(analyzer = "standard", searchAnalyzer = "standard", maxInputLength = 20)
    private Completion keywordPinyin;

    /**
     * 序列关键词补全字段
     * 与keyword功能类似，但可能用于特定序列的补全
     */
    @CompletionField(analyzer = "standard", searchAnalyzer = "standard", maxInputLength = 20)
    private Completion keywordSequence;

}
